
clear all
graph drop _all
program drop _all
macro drop _all
matrix drop _all
set more off
set type double

ssc install rdrobust
which rdrobust
*!version 9.0.5  2022-09-29
ssc install parmest
ssc install ivreg2
ssc install ranktest 
* also manually install Dcdensity package by copying the "DCdensity.ado"-file to your ado-directory from https://eml.berkeley.edu/~jmccrary/DCdensity/

* Set path as the folder where you downloaded the replication package and want to save the results
* This will be the same folder for both
* cd "path"
cd "path"

****************
*** Figure 4 ***
****************

use "Figure4.dta", replace

gen dif = partyseathare-partyvoteshare

twoway scatter dif partyvoteshare if yearmunic==2008892|| lfit dif partyvoteshare if yearmunic==2008892 , ylabel(-0.04 (0.02) 0.07) xlabel(0(0.1) 0.4) xtitle("Vote share") ytitle("Seat share - vote share") legend(off) graphregion(lcolor(white)) graphregion(fcolor(white)) plotregion(fcolor(white)) saving(right,replace)
graph save right.gph, replace

twoway scatter dif partyvoteshare if yearmunic==2012145|| lfit dif partyvoteshare if yearmunic==2012145 , ylabel(-0.04 (0.02) 0.07) xlabel(0(0.1) 0.4) xtitle("Vote share") ytitle("Seat share - vote share") legend(off) graphregion(lcolor(white)) graphregion(fcolor(white)) plotregion(fcolor(white)) saving(left,replace)
graph save left.gph, replace

graph combine left.gph right.gph, ycommon xcommon graphregion(lcolor(white)) graphregion(fcolor(white)) plotregion(fcolor(white))
graph export "Fig4.eps", as(eps) name("Graph") preview(off) replace

****************
*** Figure 5 ***
****************

* data
use "Proportionality_replication_data", clear

rdplot modifiedgallagher pop_el0 if pop_el0!=0, graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-4000(1000)8000) ylabel(0.01(0.01)0.07)) legend(off)
graph export "C:\Users\03017565\Dropbox\Proportionality\Replication\rdplot_pooled_modGall.eps", as(eps) name("Graph") preview(off) replace

rdplot differences pop_el0 if pop_el0!=0, graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-4000(1000)8000) ylabel(-0.01(0.02)0.17)) legend(off)
graph export "C:\Users\03017565\Dropbox\Proportionality\Replication\rdplot_pooled_slope.eps", as(eps)  name("Graph") preview(off) replace

***************
*** Table 1 ***
***************

* Read point estimate from Stata output row "Conventional" and confidence interval from row "Robust" 
* N within main bandwidht is sum of Eff. Number of obs left + right
rdrobust differences pop_el0 if pop_el0!=0, all 
rdrobust differences pop_el0 if pop_el0!=0, all vce(cluster munic) 
rdrobust modifiedgallagher pop_el0 if pop_el0!=0, all
rdrobust modifiedgallagher pop_el0 if pop_el0!=0, all vce(cluster munic)

* outcome mean and std.dev.
sum differences modifiedgallagher

*****************
*** Figure A5 ***
*****************

rdplot differences pop_el0 if pop_el0!=0, p(1) graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-4000(1000)8000) ylabel(-0.01(0.02)0.17)) legend(off)
graph export "C:\Users\03017565\Dropbox\Proportionality\Replication\slopeL1.eps", as(eps) name("Graph") preview(off) replace

rdplot modifiedgallagher pop_el0 if pop_el0!=0, p(1) graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-4000(1000)8000) ylabel(0.01(0.01)0.07)) legend(off)
graph export "C:\Users\03017565\Dropbox\Proportionality\Replication\mgallL1.eps", as(eps) name("Graph") preview(off) replace

*****************
*** Figure A6 ***
*****************

rdplot differences pop_el0 if pop_el0!=0 & abs(pop_el0)<=807.575, p(1) graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-1000(400)1000) ylabel(-0.01(0.02)0.17)) legend(off)
graph export "C:\Users\03017565\Dropbox\Proportionality\Replication\slopeL2.eps", as(eps) name("Graph") preview(off) replace

rdplot modifiedgallagher pop_el0 if pop_el0!=0 & abs(pop_el0)<=713.903, p(1) graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-1000(400)1000) ylabel(0.01(0.01)0.07)) legend(off)
graph export "C:\Users\03017565\Dropbox\Proportionality\Replication\mgallL2.eps", as(eps) name("Graph") preview(off) replace

****************
*** Figure 6 ***
****************

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

sum distance_all2s distance_r2s
hist distance_all2s, graphregion(color(white)) xtitle("All questions index at candidate level")
graph save histcohesionCall, replace
hist distance_r2s, graphregion(color(white)) xtitle("Redistribution index at candidate level")
graph save histcohesionCred, replace

graph combine histcohesionCall.gph histcohesionCred.gph, graphregion(color(white)) xsize(6) ysize(3) row(1)
graph export "Cohesionindiceshist.eps", as(eps) name("Graph") preview(off) replace

****************
*** Figure 7 ***
****************

rdplot meanmundist_all2s pop_el0 if tempmun==1, graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-4000(1000)8000) ylabel(0.1(0.01)0.15)) legend(off)
graph export "rdplot_pooled_allindex_new2.eps", as(eps) name("Graph") preview(off) replace

rdplot meanmundist_r2s pop_el0 if tempmun==1, graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-4000(1000)8000) ylabel(0.20(0.02)0.32))) legend(off)
graph export "rdplot_pooled_redistindex_new2.eps", as(eps) name("Graph") preview(off) replace

*****************
*** Figure A7 ***
*****************

rdplot meanmundist_all2s pop_el0 if tempmun==1, p(1) graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-4000(1000)8000) ylabel(0.1(0.01)0.15)) legend(off)
graph export "rdplotAll1.eps", as(eps) name("Graph") preview(off) replace

rdplot meanmundist_r2s pop_el0 if tempmun==1, p(1) graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-4000(1000)8000) ylabel(0.20(0.02)0.32))) legend(off)
graph export "rdplotRedist1.eps", as(eps) name("Graph") preview(off) replace


*****************
*** Figure A8 ***
*****************

rdplot meanmundist_all2s pop_el0 if tempmun==1 & abs(pop_el0)<=802.948, p(1) graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-1000(400)1000) ylabel(0.1(0.01)0.15)) legend(off)
graph export "rdplotAll2.eps", as(eps) name("Graph") preview(off) replace

rdplot meanmundist_r2s pop_el0 if tempmun==1 & abs(pop_el0)<=559.176, p(1) graph_options(graphregion(lstyle(none)) graphregion(lcolor(white)) graphregion(fcolor(white)) xlabel(-800(400)800) ylabel(0.20(0.02)0.32))) legend(off)
graph export "rdplotRedist2.eps", as(eps) name("Graph") preview(off) replace

***************
*** Table 2 ***
***************

* Read point estimate from Stata output row "Conventional" and confidence interval from row "Robust" 
* N within main bandwidht is sum of Eff. Number of obs left + right

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

* Panel A
est clear
rdrobust distance_all2s pop_el0, all  
est store rd1
rdrobust distance_all2s pop_el0, all vce(cluster munic) 
est store rd2
rdrobust distance_r2s pop_el0, all  
est store rd3
rdrobust distance_r2s pop_el0, all vce(cluster munic)
est store rd4
global tab "se(%9.3f) b(%9.3f) nogaps star(* 0.1 ** 0.05 *** 0.01) mtitles brackets"
esttab rd**, $tab compress		
* outcome mean and std.dev.
sum distance_all2s distance_r2s

* Panel B
est clear
rdrobust meanpartydist_all2s pop_el0 if tempparty==1, all  
est store rd1
rdrobust meanpartydist_all2s pop_el0 if tempparty==1, all vce(cluster munic) 
est store rd2
rdrobust meanpartydist_r2s pop_el0 if tempparty==1, all  
est store rd3
rdrobust meanpartydist_r2s pop_el0 if tempparty==1, all vce(cluster munic)
est store rd4
global tab "se(%9.3f) b(%9.3f) nogaps star(* 0.1 ** 0.05 *** 0.01) mtitles brackets"
esttab rd**, $tab compress		
* outcome mean and std.dev.
sum meanpartydist_all2s meanpartydist_r2s if tempparty==1

* Panel C
est clear
rdrobust meanmundist_all2s pop_el0 if tempmun==1, all  
est store rd1
rdrobust meanmundist_all2s pop_el0 if tempmun==1, all vce(cluster munic) 
est store rd2
rdrobust meanmundist_r2s pop_el0 if tempmun==1, all 
est store rd3
rdrobust meanmundist_r2s pop_el0 if tempmun==1, all vce(cluster munic)
est store rd4
global tab "se(%9.3f) b(%9.3f) nogaps star(* 0.1 ** 0.05 *** 0.01) mtitles brackets"
esttab rd**, $tab compress		
* outcome mean and std.dev.
sum meanmundist_all2s meanmundist_r2s if tempmun==1 

***************
*** Table 3 ***
***************

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

* Read point estimate from Stata output row "Conventional" and confidence interval from row "Robust" 
* N within main bandwidht is sum of Eff. Number of obs left + right

* Number of parties
rdrobust nroparty pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
* Effective number of parties
rdrobust effnumbparty pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
* Candidates per seat
rdrobust candsperseats pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
* Respondents
rdrobust suma pop_el0 if pop_el0!=0 & tempparty==1, all vce(cluster munic)
* Candidates
rdrobust partycands pop_el0 if pop_el0!=0 & tempparty==1, all vce(cluster munic) 
* outcome mean and std.dev.
sum nroparty effnumbparty candsperseats if tempmun==1 
sum suma partycands if tempparty==1 

* Add to letter: There were changes in the exact numbers reported in Table 3. These likely resulted from rdrobust package updates since we last had estimated those results. The changes are small in magnitude and due not affect any qualitative conclusions.

****************
*** Table A1 ***
****************

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

* Add threshold FEs

gen co1=0
replace co1=1 if pop_el>0 & pop_el<=3000
gen co2=0
replace co2=1 if pop_el>3000 & pop_el<=6000
gen co3=0
replace co3=1 if pop_el>6000 & pop_el<=11500
gen co4=0
replace co4=1 if pop_el>11500 & pop_el<=22500

/*
rdrobust distance_all2s pop_el0, covs(co2 co3 co4) all vce(cluster munic)
rdrobust distance_r2s pop_el0, covs(co2 co3 co4) all vce(cluster munic)
*/

*** Bandwidth optimized at each threshold ***

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear
keep if pop_el>0 & pop_el<=3000
rdrobust distance_all2s pop_el0 if pop_el0!=0, all vce(cluster munic)
* bw 370.659 
rdrobust distance_r2s pop_el0 if pop_el0!=0, all vce(cluster munic)
* bw 255.459

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear
keep if pop_el>3000 & pop_el<=6000
rdrobust distance_all2s pop_el0 if pop_el0!=0, all vce(cluster munic)
* bw 371.923
rdrobust distance_r2s pop_el0 if pop_el0!=0, all vce(cluster munic)
* bw 347.623

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear
keep if pop_el>6000 & pop_el<=11500
rdrobust distance_all2s pop_el0 if pop_el0!=0, all vce(cluster munic)
* bw 475.845
rdrobust distance_r2s pop_el0 if pop_el0!=0, all vce(cluster munic)
* bw 534.942

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear
keep if pop_el>11500 & pop_el<=22500
rdrobust distance_all2s pop_el0 if pop_el0!=0, all vce(cluster munic)
* bw 751.841
rdrobust distance_r2s pop_el0 if pop_el0!=0, all vce(cluster munic)
* bw 765.287

* all index
use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

drop if pop_el<(2000-370.659)
drop if pop_el>(2000+370.659) & pop_el<(4000-371.923) 
drop if pop_el>(4000+371.923) & pop_el<(8000-475.845) 
drop if pop_el>(8000+475.845) & pop_el<(15000-751.841) 
drop if pop_el>(15000+751.841) 

scatter distance_all2s pop_el, xline(2000 4000 8000 15000)

gen treat=(pop_el0>0)
gen Tpop_el0 = treat*pop_el0

gen bw=370.659  if pop_el>0 & pop_el<=3000
replace bw=371.923 if pop_el>3000 & pop_el<=6000
replace bw=475.845 if pop_el>6000 & pop_el<=11500
replace bw=751.841 if pop_el>11500 & pop_el<=22500 

gen weight=.
replace weight=(1-pop_el0/(-bw)) if pop_el0<0 & treat==0
replace weight=(1-pop_el0/bw) if pop_el0>0 & treat==1

scatter weight pop_el0

*reg distance_all2s treat pop_el0 Tpop_el0 [pw=weight], cluster(munic) 

*** Bandwidth optimized at each threshold and add cutoff FEs ***

gen co1=0
replace co1=1 if pop_el>0 & pop_el<=3000
gen co2=0
replace co2=1 if pop_el>3000 & pop_el<=6000
gen co3=0
replace co3=1 if pop_el>6000 & pop_el<=11500
gen co4=0
replace co4=1 if pop_el>11500 & pop_el<=22500

est clear
reg distance_all2s treat pop_el0 Tpop_el0 co1 co2 co3 co4 [pw=weight], cluster(munic) 
est store rdall1

*** Bandwidth optimized at each threshold, add cutoff FEs and allow different trends around each cutoff ***

gen f1=0
replace f1=1 if pop_el>0 & pop_el<2000
gen f2=0
replace f2=1 if pop_el>=2000 & pop_el<=3000
gen f3=0
replace f3=1 if pop_el>3000 & pop_el<4000
gen f4=0
replace f4=1 if pop_el>=4000 & pop_el<=6000
gen f5=0
replace f5=1 if pop_el>6000 & pop_el<8000
gen f6=0
replace f6=1 if pop_el>=8000 & pop_el<=11500
gen f7=0
replace f7=1 if pop_el>11500 & pop_el<15000
gen f8=0
replace f8=1 if pop_el>=15000 & pop_el<=22500

gen pop_el0f1=pop_el0*f1
gen pop_el0f2=pop_el0*f2
gen pop_el0f3=pop_el0*f3
gen pop_el0f4=pop_el0*f4
gen pop_el0f5=pop_el0*f5
gen pop_el0f6=pop_el0*f6
gen pop_el0f7=pop_el0*f7
gen pop_el0f8=pop_el0*f8

reg distance_all2s treat pop_el0f* co1 co2 co3 co4 [pw=weight], cluster(munic) 
est store rdall2

* redistribution index

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

drop if pop_el<(2000-255.459)
drop if pop_el>(2000+255.459) & pop_el<(4000-347.623) 
drop if pop_el>(4000+347.623) & pop_el<(8000-534.9425) 
drop if pop_el>(8000+534.942) & pop_el<(15000-765.287) 
drop if pop_el>(15000+765.287) 

scatter distance_r2s pop_el, xline(2000 4000 8000 15000)

gen treat=(pop_el0>0)
gen Tpop_el0 = treat*pop_el0
gen pop_el02=pop_el0*pop_el0
gen Tpop_el02 = treat*pop_el02

gen bw=255.459  if pop_el>0 & pop_el<=3000
replace bw=347.623 if pop_el>3000 & pop_el<=6000
replace bw=534.943 if pop_el>6000 & pop_el<=11500
replace bw=765.287 if pop_el>11500 & pop_el<=22500 

gen weight=.
replace weight=(1-pop_el0/(-bw)) if pop_el0<0 & treat==0
replace weight=(1-pop_el0/bw) if pop_el0>0 & treat==1

scatter weight pop_el0

*reg distance_r2s treat pop_el0 Tpop_el0 [pw=weight], cluster(munic) 

*** Bandwidth optimized at each threshold and add cutoff FEs ***

gen co1=0
replace co1=1 if pop_el>0 & pop_el<=3000
gen co2=0
replace co2=1 if pop_el>3000 & pop_el<=6000
gen co3=0
replace co3=1 if pop_el>6000 & pop_el<=11500
gen co4=0
replace co4=1 if pop_el>11500 & pop_el<=22500

reg distance_r2s treat pop_el0 Tpop_el0 co1 co2 co3 co4 [pw=weight], cluster(munic) 
est store rdr1

***r Bandwidth optimized at each threshold, add cutoff FEs and allow different trends around each cutoff ***

gen f1=0
replace f1=1 if pop_el>0 & pop_el<2000
gen f2=0
replace f2=1 if pop_el>=2000 & pop_el<=3000
gen f3=0
replace f3=1 if pop_el>3000 & pop_el<4000
gen f4=0
replace f4=1 if pop_el>=4000 & pop_el<=6000
gen f5=0
replace f5=1 if pop_el>6000 & pop_el<8000
gen f6=0
replace f6=1 if pop_el>=8000 & pop_el<=11500
gen f7=0
replace f7=1 if pop_el>11500 & pop_el<15000
gen f8=0
replace f8=1 if pop_el>=15000 & pop_el<=22500

gen pop_el0f1=pop_el0*f1
gen pop_el0f2=pop_el0*f2
gen pop_el0f3=pop_el0*f3
gen pop_el0f4=pop_el0*f4
gen pop_el0f5=pop_el0*f5
gen pop_el0f6=pop_el0*f6
gen pop_el0f7=pop_el0*f7
gen pop_el0f8=pop_el0*f8

reg distance_r2s treat pop_el0f* co1 co2 co3 co4 [pw=weight], cluster(munic) 
est store rdr2

global tab "se(%9.5f) b(%9.5f) nogaps star(* 0.05 ** 0.01) mtitles brackets"
esttab rd**, $tab keep(treat) compress	

*****************
*** Figure A9 ***
*****************

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

cap drop Xj Yj r0 fhat se_fhat
DCdensity pop_el if pop_el>0 & pop_el<3000 & tempmun==1, breakpoint(2000) generate(Xj Yj r0 fhat se_fhat) graphname(DCdensity_pop_el_par_2000_mun.eps)
drop Xj Yj r0 fhat se_fhat
DCdensity pop_el if pop_el>3000 & pop_el<6000 & tempmun==1, breakpoint(4000) generate(Xj Yj r0 fhat se_fhat) graphname(DCdensity_pop_el_par_4000_mun.eps)
drop Xj Yj r0 fhat se_fhat
DCdensity pop_el if pop_el>6000 & pop_el<11500 & tempmun==1, breakpoint(8000) generate(Xj Yj r0 fhat se_fhat) graphname(DCdensity_pop_el_par_8000_mun.eps)
drop Xj Yj r0 fhat se_fhat
DCdensity pop_el if pop_el>11500 & pop_el<22500 & tempmun==1, breakpoint(15000) generate(Xj Yj r0 fhat se_fhat) graphname(DCdensity_pop_el_par_15000_mun.eps)
cap drop Xj Yj r0 fhat se_fhat
DCdensity pop_el0 if tempmun==1, breakpoint(0) generate(Xj Yj r0 fhat se_fhat) graphname(DCdensity_pop_el_par_all_mun.eps)
cap drop Xj Yj r0 fhat se_fhat

******************
*** Figure A10 ***
******************

*graph distance_r, conventional
use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

rdbwselect distance_r2s pop_el0

forvalues c = 3(1)20 {

	local h=1019.302*`c'/10
	local k=587.846*`c'/10
	rdrobust distance_r2s pop_el0 if pop_el0!=0, all h(`k') b(`h')
	parmest, saving(figureA10linear`c'.dta, replace)
}

forvalues i = 3(1)20 {

	use figureA10linear`i'.dta, clear
	gen bandwidth = 587.846*`i'/10
	gen bandwidth2 = 1019.302*`i'/10
	drop if parm!="Robust"
	save, replace
}

use figureA10linear10.dta, clear

forvalues i = 3(1)20 {

	append using figureA10linear`i'.dta
	
}

sum bandwidth
local min=r(min)
local max=r(max)
local jump=r(min)*2.5
local xmin = r(min)
local xmax = r(max)

sum bandwidth2
local xmin2=r(min)
local tick=`xmin2'*2.5
local xmax2=r(max)

sort bandwidth

twoway (rline min95 max95 bandwidth, ylabel(, format(%3.2f)) lpattern(dash) lcolor(gray) lwidth(med) xaxis(1) xlabel(`xmin'(`jump')`xmax', axis(1) format(%3.1f)) legend(off) xtitle("Main bandwidth", axis(1)) ytitle(Estimated effect) graphregion(color(white)) xline(584.561, lcolor(cranberry))) (rline min95 max95 bandwidth2, lpattern(dash) lcolor(gray) lwidth(med) xaxis(2) xlabel(`xmin2'(`tick')`xmax2', axis(2) format(%3.1f)) xtitle("Bias bandwidth", axis(2)) ) (scatter estimate bandwidth, connect(direct) lwidth(med) lcolor(black) msymbol(none))
graph export "Allbw_redist_conv.eps", as(eps) name("Graph") preview(off) replace

*graph distance_r, clustered

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

rdbwselect distance_r2s pop_el0, vce(cluster munic)

forvalues c = 3(1)20 {

	local h=1118.378*`c'/10
	local k=678.774*`c'/10
	rdrobust distance_r2s pop_el0 if pop_el0!=0, all h(`k') b(`h') vce(cluster munic)
	parmest, saving(figureA10linear`c'.dta, replace)

}

forvalues i = 3(1)20 {

	use figureA10linear`i'.dta, clear
	gen bandwidth = 678.774*`i'/10
	gen bandwidth2 = 1118.378*`i'/10
	drop if parm!="Robust"
	save, replace
	
}

use figureA10linear10.dta, clear

forvalues i = 3(1)20 {

	append using figureA10linear`i'.dta
	
}

sum bandwidth
local min=r(min)
local max=r(max)
local jump=r(min)*2.5
local xmin = r(min)
local xmax = r(max)

sum bandwidth2
local xmin2=r(min)
local tick=`xmin2'*2.5
local xmax2=r(max)

sort bandwidth

twoway (rline min95 max95 bandwidth, ylabel(, format(%3.2f)) lpattern(dash) lcolor(gray) lwidth(med) xaxis(1) xlabel(`xmin'(`jump')`xmax', axis(1) format(%3.1f)) legend(off) xtitle("Main bandwidth", axis(1)) ytitle(Estimated effect) graphregion(color(white)) xline(675.257, lcolor(cranberry))) (rline min95 max95 bandwidth2, lpattern(dash) lcolor(gray) lwidth(med) xaxis(2) xlabel(`xmin2'(`tick')`xmax2', axis(2) format(%3.1f)) xtitle("Bias bandwidth", axis(2)) ) (scatter estimate bandwidth, connect(direct) lwidth(med) lcolor(black) msymbol(none))
graph export "Allbw_redist_cluster.eps", as(eps) name("Graph") preview(off) replace

*graph distance_all, conventional
use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

rdbwselect distance_all2s pop_el0

forvalues c = 3(1)20 {

	local h=819.927*`c'/10
	local k= 408.101*`c'/10
	rdrobust distance_all2s pop_el0 if pop_el0!=0, all h(`k') b(`h')
	parmest, saving(figureA10linear`c'.dta, replace)

}

forvalues i = 3(1)20 {

	use figureA10linear`i'.dta, clear
	gen bandwidth =  408.101*`i'/10
	gen bandwidth2 = 819.927*`i'/10
	drop if parm!="Robust"
	save, replace
	
}

use figureA10linear10.dta, clear

forvalues i = 3(1)20 {

	append using figureA10linear`i'.dta
	
}

sum bandwidth
local min=r(min)
local max=r(max)
local jump=r(min)*2.5
local xmin = r(min)
local xmax = r(max)

sum bandwidth2
local xmin2=r(min)
local tick=`xmin2'*2.5
local xmax2=r(max)

sort bandwidth

twoway (rline min95 max95 bandwidth, ylabel(, format(%3.2f)) lpattern(dash) lcolor(gray) lwidth(med) xaxis(1) xlabel(`xmin'(`jump')`xmax', axis(1) format(%3.1f)) legend(off) xtitle("Main bandwidth", axis(1)) ytitle(Estimated effect) graphregion(color(white)) xline( 412.975, lcolor(cranberry))) (rline min95 max95 bandwidth2, lpattern(dash) lcolor(gray) lwidth(med) xaxis(2) xlabel(`xmin2'(`tick')`xmax2', axis(2) format(%3.1f)) xtitle("Bias bandwidth", axis(2)) ) (scatter estimate bandwidth, connect(direct) lwidth(med) lcolor(black) msymbol(none))
graph export "Allbw_allind_conv.eps", as(eps) name("Graph") preview(off) replace

*graph distance_all, clustered
use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

rdbwselect distance_all2s pop_el0, vce(cluster munic)

forvalues c = 3(1)20 {

	local h=1142.987*`c'/10
	local k=692.666*`c'/10
	rdrobust distance_all2s pop_el0 if pop_el0!=0, all h(`k') b(`h') vce(cluster munic)
	parmest, saving(figureA10linear`c'.dta, replace)

}

forvalues i = 3(1)20 {

	use figureA10linear`i'.dta, clear
	gen bandwidth = 692.666*`i'/10
	gen bandwidth2 = 1142.987*`i'/10
	drop if parm!="Robust"
	save, replace
	
}

use figureA10linear10.dta, clear

forvalues i = 3(1)20 {

	append using figureA10linear`i'.dta
	
}

sum bandwidth
local min=r(min)
local max=r(max)
local jump=r(min)*2.5
local xmin = r(min)
local xmax = r(max)

sum bandwidth2
local xmin2=r(min)
local tick=`xmin2'*2.5
local xmax2=r(max)

sort bandwidth

twoway (rline min95 max95 bandwidth, ylabel(, format(%3.2f)) lpattern(dash) lcolor(gray) lwidth(med) xaxis(1) xlabel(`xmin'(`jump')`xmax', axis(1) format(%3.1f)) legend(off) xtitle("Main bandwidth", axis(1)) ytitle(Estimated effect) graphregion(color(white)) xline(689.621, lcolor(cranberry))) (rline min95 max95 bandwidth2, lpattern(dash) lcolor(gray) lwidth(med) xaxis(2) xlabel(`xmin2'(`tick')`xmax2', axis(2) format(%3.1f)) xtitle("Bias bandwidth", axis(2)) ) (scatter estimate bandwidth, connect(direct) lwidth(med) lcolor(black) msymbol(none))
graph export "Allbw_allind_cluster.eps", as(eps) name("Graph") preview(off) replace

*******************
*** Figure A 11 ***
*******************

*graph distance_r

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

rdbwselect distance_r2s pop_el0

gen pop_elfake=.
forvalues i= -20(2)20 {

replace pop_elfake=pop_el-(2000+((`i'/100)*2000)) if pop_el>0 & pop_el<=3000
replace pop_elfake=pop_el-(4000+((`i'/100)*4000)) if pop_el>3000 & pop_el<=6000
replace pop_elfake=pop_el-(8000+((`i'/100)*8000)) if pop_el>6000 & pop_el<=11500
replace pop_elfake=pop_el-(15000+((`i'/100)*15000)) if pop_el>11500 & pop_el<=22500
	
rdrobust distance_r2s pop_elfake if pop_el0!=0, all h(587.846) b(1019.301) 
parmest, saving(CCTfake`i'.dta, replace)

}

forvalues i = -20(2)20 {
	
	use CCTfake`i'.dta, clear
	gen cutoff =`i'
	drop if parm!="Robust"
	save, replace

}

use CCTfake-20.dta, clear

forvalues i = -18(2)20 {

	append using CCTfake`i'.dta
	
}

duplicates drop cutoff, force

twoway (rline min95 max95 cutoff, lpattern(dash) lcolor(gray) lwidth(med) xlabel(-20(2)20, format(%3.2g)) subtitle("A") legend(off) xtitle("Cutoff") ytitle(Estimated effect) graphregion(color(white))  xline(0, lcolor(cranberry)) yline(0, lcolor(black))) (scatter estimate cutoff, connect(direct) lwidth(med) lcolor(black) msymbol(none))
graph export "Fakecutoff_redist_conv.eps", as(eps) name("Graph") preview(off) replace

*graph distance_r2, cluster

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

rdbwselect distance_r2s pop_el0, vce(cluster munic)

gen pop_elfake=.
forvalues i= -20(2)20 {

replace pop_elfake=pop_el-(2000+((`i'/100)*2000)) if pop_el>0 & pop_el<=3000
replace pop_elfake=pop_el-(4000+((`i'/100)*4000)) if pop_el>3000 & pop_el<=6000
replace pop_elfake=pop_el-(8000+((`i'/100)*8000)) if pop_el>6000 & pop_el<=11500
replace pop_elfake=pop_el-(15000+((`i'/100)*15000)) if pop_el>11500 & pop_el<=22500
	
rdrobust distance_r2s pop_elfake if pop_el0!=0, all h(678.774) b(1118.378) vce(cluster munic)
parmest, saving(CCTfake`i'.dta, replace)

}

forvalues i = -20(2)20 {
	
	use CCTfake`i'.dta, clear
	gen cutoff =`i'
	drop if parm!="Robust"
	save, replace

}

use CCTfake-20.dta, clear

forvalues i = -18(2)20 {

	append using CCTfake`i'.dta
	
}

duplicates drop cutoff, force

twoway (rline min95 max95 cutoff, lpattern(dash) lcolor(gray) lwidth(med) xlabel(-20(2)20, format(%3.2g)) subtitle("A") legend(off) xtitle("Cutoff") ytitle(Estimated effect) graphregion(color(white))  xline(0, lcolor(cranberry)) yline(0, lcolor(black))) (scatter estimate cutoff, connect(direct) lwidth(med) lcolor(black) msymbol(none))
graph save fakecutoff_R_CCT_cluster.gph, replace
graph export "Fakecutoff_redist_cluster.eps", as(eps) name("Graph") preview(off) replace

*graph distance_all

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

rdbwselect distance_all2s pop_el0

gen pop_elfake=.
forvalues i= -20(2)20 {

replace pop_elfake=pop_el-(2000+((`i'/100)*2000)) if pop_el>0 & pop_el<=3000
replace pop_elfake=pop_el-(4000+((`i'/100)*4000)) if pop_el>3000 & pop_el<=6000
replace pop_elfake=pop_el-(8000+((`i'/100)*8000)) if pop_el>6000 & pop_el<=11500
replace pop_elfake=pop_el-(15000+((`i'/100)*15000)) if pop_el>11500 & pop_el<=22500
	
rdrobust distance_all2s pop_elfake if pop_el0!=0, all h(408.101) b(819.927) 
parmest, saving(CCTfake`i'.dta, replace)

}

forvalues i = -20(2)20 {
	
	use CCTfake`i'.dta, clear
	gen cutoff =`i'
	drop if parm!="Robust"
	save, replace

}

use CCTfake-20.dta, clear

forvalues i = -18(2)20 {

	append using CCTfake`i'.dta
	
}

duplicates drop cutoff, force

twoway (rline min95 max95 cutoff, lpattern(dash) lcolor(gray) lwidth(med) xlabel(-20(2)20, format(%3.2g)) subtitle("A") legend(off) xtitle("Cutoff") ytitle(Estimated effect) graphregion(color(white))  xline(0, lcolor(cranberry)) yline(0, lcolor(black))) (scatter estimate cutoff, connect(direct) lwidth(med) lcolor(black) msymbol(none))
graph export "Fakecutoff_allind_conv.eps", as(eps) name("Graph") preview(off) replace

*graph distance_all, cluster

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

rdbwselect distance_all2s pop_el0, vce(cluster munic)

gen pop_elfake=.
forvalues i= -20(2)20 {

replace pop_elfake=pop_el-(2000+((`i'/100)*2000)) if pop_el>0 & pop_el<=3000
replace pop_elfake=pop_el-(4000+((`i'/100)*4000)) if pop_el>3000 & pop_el<=6000
replace pop_elfake=pop_el-(8000+((`i'/100)*8000)) if pop_el>6000 & pop_el<=11500
replace pop_elfake=pop_el-(15000+((`i'/100)*15000)) if pop_el>11500 & pop_el<=22500
	
rdrobust distance_all2s pop_elfake if pop_el0!=0, all h(692.666) b(1142.987) vce(cluster munic)
parmest, saving(CCTfake`i'.dta, replace)

}

forvalues i = -20(2)20 {
	
	use CCTfake`i'.dta, clear
	gen cutoff =`i'
	drop if parm!="Robust"
	save, replace

}

use CCTfake-20.dta, clear

forvalues i = -18(2)20 {

	append using CCTfake`i'.dta
	
}

duplicates drop cutoff, force

twoway (rline min95 max95 cutoff, lpattern(dash) lcolor(gray) lwidth(med) xlabel(-20(2)20, format(%3.2g)) subtitle("A") legend(off) xtitle("Cutoff") ytitle(Estimated effect) graphregion(color(white))  xline(0, lcolor(cranberry)) yline(0, lcolor(black))) (scatter estimate cutoff, connect(direct) lwidth(med) lcolor(black) msymbol(none))
graph export "Fakecutoff_allind_cluster.eps", as(eps) name("Graph") preview(off) replace


****************
*** Table A2 ***
****************

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

* Read point estimate and standard error from row "Robust" 
* N within main bandwidht is sum of Eff. Number of obs left + right

* Panel A
* Personnel
rdrobust personnel pop_el0 if tempmun==1, all vce(cluster munic)
* Tax rate
rdrobust veropc pop_el0 if tempmun==1, all vce(cluster munic)
* Over 65yo
rdrobust yli65vpc pop_el0 if tempmun==1, all vce(cluster munic)
* Grants
rdrobust vosuuspc pop_el0 if tempmun==1, all vce(cluster munic)
* Expenditures
rdrobust expenditurepc pop_el0 if tempmun==1, all vce(cluster munic)
* Unemployment
rdrobust tyottom pop_el0 if tempmun==1, all vce(cluster munic)
* Council size
rdrobust valtuustokoko pop_el0 if tempmun==1, all vce(cluster munic)
* outcome mean and std.dev.
sum personnel veropc yli65vpc vosuuspc expenditurepc tyottom valtuustokoko if tempmun==1 

* Panel B
use "vaalikoneRDD_17022024_alliances_analysis_invidbalance.dta", clear
drop __000000
* Unemployed
rdrobust unemployed pop_el0 , all vce(cluster munic)
* University
rdrobust university pop_el0 , all vce(cluster munic)
* Male
rdrobust male pop_el0 , all vce(cluster munic)
* Old
rdrobust old pop_el0 , all vce(cluster munic)
* Incumbent
rdrobust KunnanValtuusto pop_el0 , all vce(cluster munic)
* outcome mean and std.dev.
sum unemployed university male old KunnanValtuusto

****************
*** Table A3 ***
****************

use "Proportionality_replication_data", clear
keep if pop_el>0 & pop_el<=3000
rdrobust modifiedgallagher pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust differences pop_el0 if pop_el0!=0, all vce(cluster munic) 

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear
keep if pop_el>0 & pop_el<=3000
rdrobust distance_all2s pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust distance_r2s pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust muncands pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust nroparty pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust effnumbparty pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust candsperseats pop_el0 if tempmun==1, all vce(cluster munic)
rdrobust partycands pop_el0 if pop_el0!=0 & tempparty==1, all vce(cluster munic) 
rdrobust suma pop_el0 if pop_el0!=0 & tempparty==1, all vce(cluster munic)
use "vaalikoneRDD_17022024_alliances_analysis_invidbalance.dta", clear
drop __000000
keep if pop_el>0 & pop_el<=3000
rdrobust KunnanValtuusto pop_el0 if pop_el0!=0, all vce(cluster munic)

use "Proportionality_analysis_data", clear
keep if pop_el>3000 & pop_el<=6000
rdrobust modifiedgallagher pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust differences pop_el0 if pop_el0!=0, all vce(cluster munic) 

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear
keep if pop_el>3000 & pop_el<=6000
rdrobust distance_all2s pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust distance_r2s pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust muncands pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust nroparty pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust effnumbparty pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust candsperseats pop_el0 if tempmun==1, all vce(cluster munic)
rdrobust partycands pop_el0 if pop_el0!=0 & tempparty==1, all vce(cluster munic) 
rdrobust suma pop_el0 if pop_el0!=0 & tempparty==1, all vce(cluster munic)
use "vaalikoneRDD_17022024_alliances_analysis_invidbalance.dta", clear
drop __000000
keep if pop_el>3000 & pop_el<=6000
rdrobust KunnanValtuusto pop_el0 if pop_el0!=0, all vce(cluster munic)

use "Proportionality_analysis_data", clear
keep if pop_el>6000 & pop_el<=11500
rdrobust modifiedgallagher pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust differences pop_el0 if pop_el0!=0, all vce(cluster munic) 

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear
keep if pop_el>6000 & pop_el<=11500
rdrobust distance_all2s pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust distance_r2s pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust muncands pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust nroparty pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust effnumbparty pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust candsperseats pop_el0 if tempmun==1, all vce(cluster munic)
rdrobust partycands pop_el0 if pop_el0!=0 & tempparty==1, all vce(cluster munic) 
rdrobust suma pop_el0 if pop_el0!=0 & tempparty==1, all vce(cluster munic)
use "vaalikoneRDD_17022024_alliances_analysis_invidbalance.dta", clear
drop __000000
keep if pop_el>6000 & pop_el<=11500
rdrobust KunnanValtuusto pop_el0 if pop_el0!=0, all vce(cluster munic)

use "Proportionality_analysis_data", clear
keep if pop_el>11500 & pop_el<=22500
rdrobust modifiedgallagher pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust differences pop_el0 if pop_el0!=0, all vce(cluster munic) 

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear
keep if pop_el>11500 & pop_el<=22500
rdrobust distance_all2s pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust distance_r2s pop_el0 if pop_el0!=0, all vce(cluster munic)
rdrobust muncands pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust nroparty pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust effnumbparty pop_el0 if pop_el0!=0 & tempmun==1, all vce(cluster munic)
rdrobust candsperseats pop_el0 if tempmun==1, all vce(cluster munic)
rdrobust partycands pop_el0 if pop_el0!=0 & tempparty==1, all vce(cluster munic) 
rdrobust suma pop_el0 if pop_el0!=0 & tempparty==1, all vce(cluster munic)
use "vaalikoneRDD_17022024_alliances_analysis_invidbalance.dta", clear
drop __000000
keep if pop_el>11500 & pop_el<=22500
rdrobust KunnanValtuusto pop_el0 if pop_el0!=0, all vce(cluster munic)

****************
*** Table A4 ***
****************

use "TableA4.dta", replace

* Party switching

est clear
reg abschangedaycare switcher i.munid i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid) 
est store cs1
reg abschangesoc_welfare switcher i.munid i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid) 
est store cs2
reg abschangeanti_environment switcher i.munid i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid)
est store cs3 
reg abschangeprogressive switcher i.munid i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid) 
est store cs4
reg abschangesell switcher i.munid i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid) 
est store cs5
reg abschangesubsidy switcher i.munid i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid) 
est store cs6
global tab "se(%9.4f) b(%9.4f) nogaps star(* 0.1 ** 0.05 *** 0.01) mtitles brackets"
esttab cs*, $tab compress keep(switcher _cons)

* Changes in council size

sum abschangevaltuustoko, d

reg abschangedaycare abschangevaltuustoko i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid) 
est store cvk1
reg abschangesoc_welfare abschangevaltuustoko i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid) 
est store cvk
reg abschangeanti_environment abschangevaltuustoko i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid)
est store cvk3 
reg abschangeprogressive abschangevaltuustoko i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid) 
est store cvk4
reg abschangesell abschangevaltuustoko i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid) 
est store cvk5
reg abschangesubsidy abschangevaltuustoko i.fixedpartycode KunnanValtuusto university unemployed student highprofessional male old Ika if year==2012, cluster(munid) 
est store cvk6
global tab "se(%9.4f) b(%9.4f) nogaps star(* 0.1 ** 0.05 *** 0.01) mtitles brackets"
esttab cvk*, $tab compress keep(abschangevaltuustokoko _cons)

****************
*** Table A5 ***
****************

* The results in Table A5 are calculated using rdrobust version 7.6.0 09-25-20. Current version does not calculate the optimal bandwidths due to mass point issue
*. which rdrobust
*c:\ado\plus\r\rdrobust.ado
*!version 7.6.0  09-25-20

use "TableA5.dta", clear
gen pop_el0=.
replace pop_el0=population-2000 if population>0 & population<=3000
replace pop_el0=population-4000 if population>3000 & population<=6000
replace pop_el0=population-8000 if population>6000 & population<=11500
replace pop_el0=population-15000 if population>11500 & population<=22500
replace pop_el0=population-30000 if population>22500 & population<=45000
replace pop_el0=population-60000 if population>45000 & population<=90000
replace pop_el0=population-120000 if population>90000 & population<=185000
replace pop_el0=population-250000 if population>185000 & population<=325000
replace pop_el0=population-400000 if population>325000

rdrobust distance_all2s pop_el0, all
rdrobust distance_all2s pop_el0, all vce(cluster munic)
rdrobust distance_r2s pop_el0, all
rdrobust distance_r2s pop_el0, all vce(cluster munic)

****************
*** Table A6 ***
****************

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

* Read point estimate from Stata output row "Conventional" and confidence interval from row "Robust" 
* N within main bandwidht is sum of Eff. Number of obs left + right

rdrobust distance_all2s pop_el0 if valittu==1, all
rdrobust distance_all2s pop_el0 if valittu==1, all vce(cluster munic)
rdrobust distance_r2s pop_el0 if valittu==1, all
rdrobust distance_r2s pop_el0 if valittu==1, all vce(cluster munic)

****************
*** Table A7 ***
****************

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear
keep if tempmun==1
duplicates drop
merge 1:1 year munic using "Proportionality_replication_data.dta"
drop if _merge==2
drop _merge

*** Municipal level ***

* IV
drop if pop_el0>22500
gen treatmentvar=0
replace treatmentvar=1 if pop_el0>0
gen popelabove=treatmentvar*pop_el0

* mod gallagher

est clear
eststo: ivreg2  meanmundist_all2s (modifiedgallagher=treatmentvar) pop_el0 popelabove, cluster(munic) first
estadd scalar f_test1 =  e(first)[8,1]
eststo: ivreg2  meanmundist_all2s (modifiedgallagher=treatmentvar) pop_el0 popelabove if abs(pop_el0)<=802.948, cluster(munic) first
estadd scalar f_test2 =  e(first)[8,1]
eststo: ivreg2  meanmundist_r2s (modifiedgallagher=treatmentvar) pop_el0 popelabove, cluster(munic) first
estadd scalar f_test4 =  e(first)[8,1]
eststo: ivreg2  meanmundist_r2s (modifiedgallagher=treatmentvar) pop_el0 popelabove if abs(pop_el0)<=550.371, cluster(munic) first
estadd scalar f_test4 =  e(first)[8,1]
esttab , b(3) se(3) keep(modifiedgallagher) star(* 0.1 ** 0.05 *** 0.01) stats(N f_test1 f_test2 f_test3 f_test4)

sum meanmundist_all2s meanmundist_r2s
sum meanmundist_all2s if abs(pop_el0)<=802.948
sum meanmundist_r2s if abs(pop_el0)<=550.371

* corresponding OLS
est clear
reg  meanmundist_all2s modifiedgallagher pop_el0 popelabove, cluster(munic)
est store ols1
reg  meanmundist_all2s modifiedgallagher pop_el0 popelabove if abs(pop_el0)<=802.948, cluster(munic)
est store ols2
reg  meanmundist_r2s modifiedgallagher pop_el0 popelabove, cluster(munic)
est store ols3
reg  meanmundist_r2s modifiedgallagher pop_el0 popelabove if abs(pop_el0)<=550.371, cluster(munic)
est store ols4
global tab "se(%9.3f) b(%9.3f) nogaps star(* 0.1 ** 0.05 *** 0.01) mtitles brackets"
esttab ols**, $tab compress

****************
*** Table A8 ***
****************

* slope index

est clear
eststo: ivreg2  meanmundist_all2s (differences=treatmentvar) pop_el0 popelabove, cluster(munic) first
estadd scalar f_test1 =  e(first)[8,1]
eststo: ivreg2  meanmundist_all2s (differences=treatmentvar) pop_el0 popelabove if abs(pop_el0)<=802.948, cluster(munic) first
estadd scalar f_test2 =  e(first)[8,1]
eststo: ivreg2  meanmundist_r2s (differences=treatmentvar) pop_el0 popelabove, cluster(munic) first
estadd scalar f_test3 =  e(first)[8,1]
eststo: ivreg2  meanmundist_r2s (differences=treatmentvar) pop_el0 popelabove if abs(pop_el0)<=550.371, cluster(munic) first
estadd scalar f_test4 =  e(first)[8,1]
esttab , b(3) se(3) keep(differences) star(* 0.1 ** 0.05 *** 0.01) stats(N f_test1 f_test2 f_test3 f_test4)

sum meanmundist_all2s meanmundist_r2s
sum meanmundist_all2s if abs(pop_el0)<=802.948
sum meanmundist_r2s if abs(pop_el0)<=550.371

* corresponding OLS
est clear
reg  meanmundist_all2s differences pop_el0 popelabove, cluster(munic) first
est store ols1
reg  meanmundist_all2s differences pop_el0 popelabove if abs(pop_el0)<=802.948, cluster(munic) first
est store ols2
reg  meanmundist_r2s differences pop_el0 popelabove, cluster(munic) first
est store ols3
reg  meanmundist_r2s differences pop_el0 popelabove if abs(pop_el0)<=550.371, cluster(munic) first
est store ols4
global tab "se(%9.3f) b(%9.3f) nogaps star(* 0.1 ** 0.05 *** 0.01) mtitles brackets"
esttab ols**, $tab compress

****************
*** Table A9 ***
****************

use "responserates.dta", clear

sum male Ika KunnanValtuusto aanetyht valittu university unemployed old if _merge!=3
sum male Ika KunnanValtuusto aanetyht valittu university unemployed old if _merge==3

******************
*** Figure A12 ***
******************

use "responserates.dta", clear
drop __000001

gen VAA=(_merge==3)

gen all=1
bysort munid party year: egen sumparty=sum(all)
bysort munid year: egen summunid=sum(all)

bysort munid party year: egen sumpartyVAAtemp=sum(all) if VAA==1
bysort munid party year: egen sumpartyVAA=mean(sumpartyVAAtemp)
drop sumpartyVAAtemp
bysort munid year: egen summunidVAAtemp=sum(all) if VAA==1
bysort munid year: egen summunidVAA=mean(summunidVAAtemp) 
drop summunidVAAtemp

gen VAAshareparty=sumpartyVAA/sumparty
gen VAAsharemunid=summunidVAA/summunid

by year munid party, sort: gen partytemp=1 if _n==1 
by year munid, sort: gen muntemp=1 if _n==1 

hist VAAshareparty if partytemp==1, graphregion(color(white)) xtitle("VAA resp. share by party")
graph save VAAshareparty1, replace
hist VAAsharemunid if muntemp==1, graphregion(color(white)) xtitle("VAA resp. share by municipality")
graph save VAAsharemunid, replace
hist VAAshareparty if partytemp==1 & (party=="KESK" | party=="KOK" | party=="SDP"), graphregion(color(white)) xtitle("VAA resp. share by (large) party") 
graph save VAAshareparty2.gph, replace
graph combine VAAshareparty1.gph VAAshareparty2.gph VAAsharemunid.gph, graphregion(color(white)) xsize(8) ysize(3.5) row(1)
graph export "VAAresponseshares.eps", as(eps) name("Graph") preview(off) replace


******************
*** Figure A13 ***
******************

use "vaalikoneRDD_17022024_alliances_analysis_s.dta", clear

* Panel A
sum personnel veropc yli65vpc vosuuspc expenditurepc tyottom pop_el if tempmun==1
* Panel B
sum valtuustokoko muncands nroparty effnumbparty meanmundist_r2s meanmundist_all2s if tempmun==1
* Panel C
sum partyvoteshare suma partycands candsperseats meanpartydist_r2s meanpartydist_all2s if tempparty==1
* Panel D
sum distance_all2s distance_r2s 
use "vaalikoneRDD_17022024_alliances_analysis_invidbalance.dta", clear
sum unemployed university male old KunnanValtuusto 



